window.onload = function(){
    
}

function onBtnCall(){
    var uname = document.getElementById('uname');
    var upwd = document.getElementById('upwd');
    var upwd_2 = document.getElementById('upwd_2');

    xmlhttp = new XMLHttpRequest();
    if (!xmlhttp) { // 异常，创建对象实例失败
        window.alert("不能创建XMLHttpRequest对象实例.");
        return false;
    }

    if (uname.value == "") {
        window.alert("用户名为空");
        return false;
    }

    if (upwd.value == "" || upwd_2.value == "") {
        window.alert("密码不能为空");
        return false;
    }

    if (upwd.value != upwd_2.value) {
        window.alert("密码必须一致");
        return false;
    }

    xmlhttp.open("POST","http://127.0.0.1/controller/registered_user.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("name="+uname.value+"&password="+upwd.value);
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            var json = JSON.parse(xmlhttp.responseText);
            if (Number(json.status) == 0) {
                console.log(json.data);
                //window.open(json.data, '_blank');
                location.href = json.data;
            }
        }
    }
    return false;
}